﻿#include "HNHomeScence.h"
#include "HNScenceManager.h"
#include "Game/GameLib.h"
#include "JniCross/JniFun.h"
#include "../Game/HNMJSoundFun.h"

#include "../Game/HNMJGameScence.h"
#include "../Game/HNMJPlayer.h"
#include "../Game/HNMJSoundFun.h"
#include "Game/Widget/SliderMenu.h"

FV_SINGLETON_STORAGE(HNHomeScence);

HNHomeScence::HNHomeScence()
	:m_kPublicNoticMission(ScriptData<std::string>("address").Value().c_str(),ScriptData<int>("Port").Value())
	,m_kFaceMission(ScriptData<std::string>("address").Value().c_str(),ScriptData<int>("Port").Value())
	,m_kIndividualMission(ScriptData<std::string>("address").Value().c_str(),ScriptData<int>("Port").Value())
{
	init();
	CServerListData::shared()->SetServerListDataSink(this);
	UserInfo::Instance().addUpPlayerInfoCB(this,QY_CALLFUNC_SELECTOR(HNHomeScence::upPlayerInfo));
	UserInfo::Instance().addLoginSucessCB(this,QY_CALLFUNC_SELECTOR(HNHomeScence::LogonSucess));
	m_kPublicNoticMission.setMissionSink(this);
	m_kIndividualMission.setMissionSink(this);

}
void HNHomeScence::button_laizi(cocos2d::Ref*,WidgetUserInfo* pInfo)
{
	WidgetFun::setVisible(this,"RecordListPlane",false);
	WidgetFun::setVisible(this,"RecordListPlane1",true);
}
void HNHomeScence::button_guangdong(cocos2d::Ref*,WidgetUserInfo* pInfo)
{
	WidgetFun::setVisible(this,"RecordListPlane1",false);
	WidgetFun::setVisible(this,"RecordListPlane",true);
}
HNHomeScence::~HNHomeScence()
{

}
bool HNHomeScence::init()
{
	if (!cocos2d::CCNode::init())
	{
		return false;
	};
	WidgetScenceXMLparse kScence1("Script/HNHomeScence.xml",this);

	init_Button();
	if (WidgetFun::getChildWidget(this,"GameSetPlane") == NULL)
	{
		return true;
	}
	
	WidgetManager::addButtonCB("HNMJ_SetBarSider1",this,button_selector(HNMJGameScence::SetBarSider1));
	WidgetManager::addButtonCB("HNMJ_SetBarSider2",this,button_selector(HNMJGameScence::SetBarSider2));
	
	WidgetManager::addButtonCB("HNMJ_Button_Cheak_ChangSha",this,button_selector(HNMJGameScence::HNMJ_Button_Hua));
	WidgetManager::addButtonCB("HNMJ_Button_Cheak_PuTong",this,button_selector(HNMJGameScence::HNMJ_Button_Hua));
	
	WidgetManager::addButtonCB("setting_min_sound_sign2",this,button_selector(HNMJGameScence::setting_min_sound_sign2));
	WidgetManager::addButtonCB("setting_min_sound_sign1",this,button_selector(HNMJGameScence::setting_min_sound_sign1));
	

	std::string kIdex = cocos2d::UserDefault::getInstance()->getStringForKey("Hua","1");
	if (kIdex == "0")
	{
		HNMJSoundFun::setPuTong(false);
		WidgetFun::setChecked(this,"HNMJ_Button_Cheak_ChangSha",true);
		WidgetFun::setChecked(this,"HNMJ_Button_Cheak_PuTong",false);
	}
	else
	{
		HNMJSoundFun::setPuTong(true);
		WidgetFun::setChecked(this,"HNMJ_Button_Cheak_ChangSha",false);
		WidgetFun::setChecked(this,"HNMJ_Button_Cheak_PuTong",true);
	}
	cocos2d::Node* pRootNode = this;
	{
		float fTime =cocos2d::UserDefault::getInstance()->getFloatForKey("SetBar1",0.7f);
		fTime =fTime*100;
		cocos2d::SliderMenu* pSlider = WidgetFun::castNode<cocos2d::SliderMenu>(WidgetFun::getChildWidget(pRootNode,"SetBarSider1"));
		
		pSlider->setActValue(fTime);
		WidgetFun::setProgress(pRootNode,"SetBar1",fTime,100);
		SoundFun::Instance().SetSoundEffect(fTime/pSlider->getMaxValue());
	}

	{
		float fTime =cocos2d::UserDefault::getInstance()->getFloatForKey("SetBar2",0.7f);
		fTime =fTime*100;
		cocos2d::SliderMenu* pSlider = WidgetFun::castNode<cocos2d::SliderMenu>(WidgetFun::getChildWidget(pRootNode,"SetBarSider2"));
	    pSlider->setActValue(fTime);
		WidgetFun::setProgress(pRootNode,"SetBar2",fTime,100);
		SoundFun::Instance().SetSoundBackground(fTime/pSlider->getMaxValue());
	
		
	}	
	return true;
}
void HNHomeScence::hideAll()
{
	WidgetFun::setVisible(this,"HomeScencePlane",false);
	WidgetFun::setVisible(this,"WanFaNode",false);
	WidgetFun::setVisible(this,"PlayerInfoNode",false);
	WidgetFun::setVisible(this,"GameSetPlane",false);
}
void HNHomeScence::EnterScence()
{
	WidgetFun::setVisible(this,"HomeScencePlane",true);
	upPlayerInfo();
	HNMJSoundFun::playBackMusic("csmj.mp3"); 
}
void HNHomeScence::upPlayerInfo()
{
	utility::log("SCHomeScence::upPlayerInfo()");	
	WidgetFun::setText(this,"HomeID",utility::paseInt(UserInfo::Instance().getUserID(),6));
	WidgetFun::setText(this,"HomeName",UserInfo::Instance().getUserNicName());
	WidgetFun::setText(this,"Ka",utility::toString(UserInfo::Instance().getUserInsure()));
	ImagicDownManager::Instance().addDown(WidgetFun::getChildWidget(this,"HeadImagic"),
		UserInfo::Instance().getHeadHttp(),UserInfo::Instance().getUserID());

}
void HNHomeScence::LogonSucess()
{
	m_kIndividualMission.query(UserInfo::Instance().getUserID());

	m_kPublicNoticMission.PublicNotice("HN_SC_NOTICE");
	m_kPublicNoticMission.PublicNotice("Home_Msg_NOTICE");
	m_kPublicNoticMission.PublicNotice("NC_SHOP_TXT");
	
	


}
void HNHomeScence::upGameSever()
{

}
void HNHomeScence::initSetButton()
{
}
void HNHomeScence::SetBarSider1(cocos2d::Ref* pNode,WidgetUserInfo*)
{
	
	cocos2d::SliderMenu* pSlider = WidgetFun::castNode<cocos2d::SliderMenu>((Node*)pNode);
	SoundFun::Instance().SetSoundEffect(pSlider->getValue()/pSlider->getMaxValue());
	cocos2d::UserDefault::getInstance()->setFloatForKey("SetBar1",pSlider->getValue()/100.0f);
}


void HNHomeScence::SetBarSider2(cocos2d::Ref* pNode,WidgetUserInfo* pUserInfo)
{
	
	cocos2d::SliderMenu* pSlider = WidgetFun::castNode<cocos2d::SliderMenu>((Node*)pNode);
	SoundFun::Instance().SetSoundBackground(pSlider->getValue()/pSlider->getMaxValue());
	cocos2d::UserDefault::getInstance()->setFloatForKey("SetBar2",pSlider->getValue()/100.0f);
}

void HNHomeScence::setting_min_sound_sign2(cocos2d::Ref* pNode,WidgetUserInfo* pUserInfo)
{

	cocos2d::Node* pRootNode = this;
	
	{
		float fTime =cocos2d::UserDefault::getInstance()->getFloatForKey("SetBar2",0.0f);
		fTime =fTime*100;
		cocos2d::SliderMenu* pSlider = WidgetFun::castNode<cocos2d::SliderMenu>(WidgetFun::getChildWidget(pRootNode,"SetBarSider2"));
	    pSlider->setActValue(fTime);
		WidgetFun::setProgress(pRootNode,"SetBar2",fTime,100);
		SoundFun::Instance().SetSoundBackground(fTime/pSlider->getMaxValue());
	
		
	}
	

}
void HNHomeScence::setting_min_sound_sign1(cocos2d::Ref* pNode,WidgetUserInfo* pUserInfo)
{

	cocos2d::Node* pRootNode = this;
	
	{
		float fTime =cocos2d::UserDefault::getInstance()->getFloatForKey("SetBar1",0.0f);
		fTime =fTime*100;
		cocos2d::SliderMenu* pSlider = WidgetFun::castNode<cocos2d::SliderMenu>(WidgetFun::getChildWidget(pRootNode,"SetBarSider1"));
		pSlider->setActValue(fTime);
		WidgetFun::setProgress(pRootNode,"SetBar1",fTime,100);
		SoundFun::Instance().SetSoundEffect(fTime/pSlider->getMaxValue());
		
	}
	

}
void HNHomeScence::setting_max_sound_sign2(cocos2d::Ref* pNode,WidgetUserInfo* pUserInfo)
{

	cocos2d::Node* pRootNode = this;
	
	{
		float fTime =cocos2d::UserDefault::getInstance()->getFloatForKey("SetBar2",1.0f);
		fTime =fTime*100;
		cocos2d::SliderMenu* pSlider = WidgetFun::castNode<cocos2d::SliderMenu>(WidgetFun::getChildWidget(pRootNode,"SetBarSider2"));
	    pSlider->setActValue(fTime);
		WidgetFun::setProgress(pRootNode,"SetBar2",fTime,100);
		SoundFun::Instance().SetSoundBackground(fTime/pSlider->getMaxValue());
	
		
	}
	

}
void HNHomeScence::setting_max_sound_sign1(cocos2d::Ref* pNode,WidgetUserInfo* pUserInfo)
{

	cocos2d::Node* pRootNode = this;
	
	{
		float fTime =cocos2d::UserDefault::getInstance()->getFloatForKey("SetBar1",1.0f);
	    fTime =fTime*100;
		cocos2d::SliderMenu* pSlider = WidgetFun::castNode<cocos2d::SliderMenu>(WidgetFun::getChildWidget(pRootNode,"SetBarSider1"));
		pSlider->setActValue(fTime);
		WidgetFun::setProgress(pRootNode,"SetBar1",fTime,100);
		SoundFun::Instance().SetSoundEffect(fTime/pSlider->getMaxValue());
	
		
	}
	

}